package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Hotel;
import cn.wolfcode.trip.base.mapper.HotelMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IHotelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotelServiceImpl implements IHotelService {
    @Autowired
    private HotelMapper hotelMapper;

    @Override
    public List<Hotel> listCommend() {
        return hotelMapper.selectCommend();
    }

    @Override
    public List<Hotel> listHotel(QueryObject qo) {
        return hotelMapper.query(qo);
    }

    @Override
    public PageInfo<Hotel> query(QueryObject qo) {

        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Hotel> list = hotelMapper.queryForList(qo);


        return new PageInfo<>(list);

    }




    @Override
    public void saveOrUpdate(Hotel hotel) {
        if (hotel.getId()!=null) {
            hotelMapper.updateByPrimaryKey(hotel);
        }else{
            hotelMapper.insert(hotel);
        }

    }

    @Override
    public void delete(Long id) {
        hotelMapper.deleteByPrimaryKey(id);

    }

    @Override
    public Hotel selectByPrimaryKey(Long id) {
        return hotelMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Hotel> selectAll() {
        return hotelMapper.selectAll();
    }
}
